package _11_整理题目._2_二叉树_递归_dfs_bfs._递归;

import org.junit.Test;
import util.TreeNode;


/**
 * https://leetcode-cn.com/problems/invert-binary-tree/
 *
 * 操作给定的二叉树，将其变换为源二叉树的镜像。
 * 
 */
public class _06_镜像翻转二叉树 {
    
    public TreeNode invertTree(TreeNode root) {
        if (root == null) return null;
        
        TreeNode temp = root.left;
        root.left = root.right;
        root.right = temp;

        invertTree(root.left);
        invertTree(root.right);

        return root;
    }
    
    @Test
    public void main() {
        Integer[] input = {8, 6, 10, 5, 7, 9, 11};
        TreeNode root = TreeNode.getTreeFromArray(input);
        TreeNode.printTree(root);
        TreeNode result = invertTree(root);
        TreeNode.printTree(result);
    }
}
